<template>
    <view style="height: 100%">
        <s-nav title="死亡证明"></s-nav>
        <s-content>
            <uni-forms ref="form" :modelValue="formData" :rules="rules">
                <s-card style="padding:12px 0">
                    <view class="cus-margin border">
                        <uni-forms-item  label="姓名" name="name" required label-width="80">
                            <uni-easyinput v-model="formData.name" :inputBorder="false" placeholder="请输入" placeholderStyle="color: #888888;text-align:right;" />
                        </uni-forms-item>
                    </view>
                    <view class="cus-margin border">
                        <uni-forms-item  label="性别" name="gender" required label-width="80">
                            <s-picker placeholder="请选择" @change="change($event, 'gender')"  :dataSet="genderData" ></s-picker>
                            <!-- <uni-easyinput v-model="formData.gender" :inputBorder="false" placeholder="请输入" placeholderStyle="color: #888888;text-align:right;" /> -->
                        </uni-forms-item>
                    </view>
                    <view class="cus-margin border">
                        <uni-forms-item  label="详址" name="address" required label-width="80">
                            <uni-easyinput v-model="formData.address" :inputBorder="false" placeholder="请输入" placeholderStyle="color: #888888;text-align:right;" />
                        </uni-forms-item>
                    </view>
                    <view class="cus-margin border">
                        <uni-forms-item  label="身份证号" name="cardNum"  required label-width="80">
                            <uni-easyinput v-model="formData.cardNum" :inputBorder="false" placeholder="请输入" placeholderStyle="color: #888888;text-align:right;" />
                        </uni-forms-item>
                    </view>
                    <view class="cus-margin">
                        <uni-forms-item  label="死亡日期" name="deathDate" required label-width="80">
                            <uni-datetime-picker :border="false" type="date" :value="single" @change="(e)=>change(e,'deathDate')"/>
                        </uni-forms-item>
                    </view>
                </s-card>
                <button type="primary" style="margin: 348rpx 24rpx 0 24rpx; background-color: #02B494;" @click="submit()">提交</button>
            </uni-forms>
        </s-content>
    </view>
</template>

<script>
import { REQUEST_SUCCESS_CODE } from '../../constant';
import { post } from '../../utils/request';
export default {
    data(){
        return {
            params:{},
            formData: {},
            rules:{
                name: {
                    rules: [{
                        required: true,
                        errorMessage: '姓名不能为空'
                    }]
                },
                gender: {
                    rules: [{
                        required: true,
                        errorMessage: '性别不能为空'
                    }]
                },
                address: {
                    rules: [{
                        required: true,
                        errorMessage: '详址不能为空'
                    }]
                },
                cardNum: {
                    rules: [{
                        required: true,
                        errorMessage: '身份证号不能为空'
                    }]
                },
                deathDate: {
                    rules: [{
                        required: true,
                        errorMessage: '死亡日期不能为空'
                    }]
                },
            },
            genderData:['男','女'],
        }
    },
    onLoad(param){
       const params = JSON.parse(param.params);
       this.params = params;
    },
    methods:{
        // 提交申请
        async submit () {
            const value = await this.$refs.form.validate();
            const result = await post('/api/application/xsbsCertifyInfo/app/saveCertifyInfo',{...this.params,...value});
            if(result.code === REQUEST_SUCCESS_CODE) {
                uni.navigateBack({delta: 2})
            }
        },
        change(e,code){
            this.$refs.form.setValue(code,e);
        }
    }
}
</script>

<style lang="scss">
.cus-margin {
    padding: 0 24rpx;
    .uni-forms-item {
        margin-top: 10rpx;
        margin-bottom: 10rpx;
    }
    .uni-forms-item__error {
        top: 25%;
    }

    .icon-calendar {
        display: none;
    }
    .uni-date__x-input {
        text-align: right;
    }
    .picker-text {
        color: #888888;
    }
}
.border {
    border-bottom: 2rpx solid #E8E8E8;
}
   
</style>